package com.zbkj.crmeb.merchant.admin.controller;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.crmeb.core.common.CommonResult;
import com.factory.CommonFactory;
import com.github.pagehelper.PageInfo;
import com.utils.CrmebUtil;
import com.zbkj.crmeb.finance.model.UserRecharge;
import com.zbkj.crmeb.finance.service.UserRechargeService;
import com.zbkj.crmeb.front.request.UserRechargeRequest;
import com.zbkj.crmeb.merchant.api.controller.ApiBaseController;
import com.zbkj.crmeb.order.pprocess.IOrangePayOrderProcess;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商户充值
 * @Description: 
 * @author daigb
 * @date 2021-09-02
 */
@RestController
@RequestMapping("api/admin/mer/recharge")
@Api(tags = "商户线上充值")
public class MerRechargeController extends ApiBaseController {
    @Autowired
    private CommonFactory commonFactory;
    @Autowired
    UserRechargeService userRechargeService;

    /**
     * 充值
     * @Description:  
     * @author daigb 
     * @param @param httpServletRequest
     * @param @param request
     * @param @return
     * @param @throws Exception
     * @return CommonResult<Map<String,Object>>
     * @throws
     */
    @ApiOperation(value = "线上扫码充值")
    @RequestMapping(value = "/img", method = RequestMethod.POST)
    public CommonResult<Object> routineRecharge(HttpServletRequest httpServletRequest, @RequestBody UserRechargeRequest request) throws Exception {
        IOrangePayOrderProcess orderProcess = commonFactory.getPayType("weixin");
        UserRecharge userRecharge = orderProcess.createImgRecharge(request.getPrice());
        
        return CommonResult.success(userRecharge);
    }
    
//    @ApiOperation(value = "转出到可用余额")
//    @RequestMapping(value = "/withdraw/account", method = RequestMethod.POST)
//    public CommonResult<Object> withdrawAccount(HttpServletRequest httpServletRequest, @RequestBody UserRechargeRequest userRechargeRequest, HttpServletRequest request) throws Exception {
//        boolean b = userRechargeService.withdrawAccount(userRechargeRequest.getPrice(), CrmebUtil.getClientIp(request));
//        if(b) {
//            return CommonResult.success();
//        } else {
//            return CommonResult.failed();
//        }
//    }
    
    /**
     * 分页查询
     * @Description:  
     * @author daigb 
     * @param @param storeBrandRequest
     * @param @return
     * @return CommonResult<Object>
     * @throws
     */
    @ApiOperation(value = "订单分页")
    @PostMapping("/page")
    public CommonResult<Object> pageEntity(@RequestBody UserRechargeRequest request, HttpServletRequest servletRequest) {
        request.setMerId(getMerId(servletRequest));
        request.setType(true);
        PageInfo<UserRecharge> page = userRechargeService.pageEntity(request);
        
        return CommonResult.success(page);
    }
    
    /**
     * 查看详情
     * @Description:  
     * @author daigb 
     * @param @param storeBrandRequest
     * @param @return
     * @return CommonResult<Object>
     * @throws
     */
    @ApiOperation(value = "查看订单详情")
    @GetMapping("/info/{id}")
    public CommonResult<UserRecharge> pageEntity(@PathVariable Integer id, HttpServletRequest servletRequest) {
        UserRecharge response = userRechargeService.getById(id);
        
        return CommonResult.success(response);
    }

}



